package com.base.helper;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.beust.jcommander.internal.Maps;
import com.base.po.czb_sdk.CZBUtil;
import org.apache.commons.lang3.StringUtils;


import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;

public class RYSmsHelper {

    public static final String GET_URL = "http://47.111.98.25:7862/sms";
    final static String account = "420065";
    final static String password = "J3PRzf";

    final static String extno = "10690889147";//接入码
    final static String rt = "json";//xml/json
//    final static String mobile  = "18055603791";

//    public static String userName = "hzsbdznkj";
//    public static String password = MD5Util.MD5Encode(userName + MD5Util.MD5Encode("u23uby", "utf-8"), "utf-8");
//
//    public static String url = "http://api.sms.mas521.com:9000/smsSend.do";
    public static void main(String[] args) throws UnsupportedEncodingException {
        Map<String, Object> map = Maps.newHashMap();
        map.put("account", account);
        map.put("password", password);
        map.put("mobile", "17674612951");
        map.put("extno",extno);
        map.put("action","send");
        map.put("rt",rt);
        map.put("content", URLEncoder.encode("【zh】尊敬的用户您好:,如非本人操作,请忽略本短信", "UTF-8"));
        String param = CZBUtil.getParam(map, null);
        WebHelper.GetData(GET_URL, param);
//        sendSms("18055603791","zh",2863);
    }
    /**
     * 上海任毅短信
     *
     * @param mobile  手机号码
     * @param parentName 代理商
     * @param num 验证码
     * @return
     */
    public static String sendSms(String mobile, String parentName, Integer num) {
        String json = null;

        try {
            Map<String, Object> map = Maps.newHashMap();
            map.put("account", account);
            map.put("password", password);
            map.put("mobile", mobile);
            map.put("extno",extno);
            map.put("action","send");
            map.put("rt",rt);
            map.put("content", URLEncoder.encode("【" + parentName + "】尊敬的用户您好:您本次验证码为:" + num + ",如非本人操作,请忽略本短信", "UTF-8"));
            String param = CZBUtil.getParam(map, null);
            json = WebHelper.GetData(GET_URL, param);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        JSONObject returnjson=JSONObject.parseObject(json.toString());
        String resultType=returnjson.getString("status");
//        if (!StringUtils.isEmpty(resultList)){
//            JSONArray listArray=JSONArray.parseArray(resultList);
//            if (listArray.size()>0){
//                JSONObject object=JSONObject.parseObject(listArray.get(0).toString());
//                return object.getString("mid");
//            }
//        }

        return resultType;
    }

    /**
     * 上海任毅短信
     *
     * @param mobile  手机号码
     * @param parentName 代理商
     * @param money 充值金额
     * @param type 充值类型 1空中充值 2充值卡 3支付宝 4微信
     * @return
     */
    public static String sendRecharge(String mobile, String parentName, Integer money, Integer type) {
        String json = null;

        String rechargeType = "";
        switch (type){
            case 1:
                rechargeType = "空中充值";
                break;
            case 2:
                rechargeType = "充值卡";
                break;
            case 3:
                rechargeType = "支付宝";
                break;
            case 4:
                rechargeType = "微信";
                break;
        }

        try {
            Map<String, Object> map = Maps.newHashMap();
            map.put("account", account);
            map.put("password", password);
            map.put("mobile", mobile);
            map.put("extno",extno);
            map.put("action","send");
            map.put("rt",rt);
            map.put("content", URLEncoder.encode("【" + parentName + "】尊敬的用户您好：您本次通过" + rechargeType + "充值金额为：" + money + ",金额已到账，请您登陆软件查看，如非本人操作，请忽略本短信", "UTF-8"));
            String param = CZBUtil.getParam(map, null);
            json = WebHelper.GetData(GET_URL, param);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        return json;
    }

    /**
     * 上海任毅短信  购物成功提示
     *
     * @param mobile  手机号码
     * @param parentName 代理商
     * @param money 充值金额
     * @param type 充值类型 3支付宝 4微信
     * @return
     */
    public static String sendMemberPay(String mobile, String parentName, Integer money, Integer type) {
        String json = null;

        String rechargeType = "";
        switch (type){
            case 1:
                rechargeType = "空中充值";
                break;
            case 2:
                rechargeType = "充值卡";
                break;
            case 3:
                rechargeType = "支付宝";
                break;
            case 4:
                rechargeType = "微信";
                break;
        }

        try {
            Map<String, Object> map = Maps.newHashMap();
            map.put("account", account);
            map.put("password", password);
            map.put("mobile", mobile);
            map.put("extno",extno);
            map.put("action","send");
            map.put("rt",rt);
            map.put("content", URLEncoder.encode("【" + parentName + "】尊敬的用户您好：感谢您本次通过"+rechargeType+"购买的"+money+"元会员套餐,请您登陆软件查看资金到账情况，如非本人操作，请忽略本短信", "UTF-8"));
            String param = CZBUtil.getParam(map, null);
            json = WebHelper.GetData(GET_URL, param);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        return json;
    }
}
